function t(t) {
  return t && t.__esModule ? t : {
    default: t
  };
}

var a = Object.assign || function(t) {
    for (var a = 1; a < arguments.length; a++) {
      var e = arguments[a];
      for (var i in e) Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i]);
    }
    return t;
  },
  e = t(require("../../api/api.js")),
  i = t(require("../../utils/util.js")),
  r = t(require("../../utils/filter.js")),
  s = require("../../config/constants.js"),
  n = require("../../data/translate.js"),
  config = require('../../config'),

  c = getApp();

Page({
  data: {
    service_type: ["现场服务","微信服务"],
    cater_info: "",
    page: 1,
    hasMore: !0,
    teacher_list: [],
    teacher_list_length: 0,
    COUNTRIES_VIA_LANGUAGE: n.COUNTRIES_VIA_LANGUAGE,
    TEACH_TIME_DATUM: n.TEACH_TIME_DATUM,
    TEACHER_TAG_DATUM: n.TEACHER_TAG_DATUM,
    TEACHER_TYPES: n.TEACHER_TYPES,
    TEACHER_CHILD_TAGS: [],
    ALL_LANGUAGE_DATUM: n.ALL_LANGUAGE_DATUM,
    TEACHER_PRICE_VALUE: 0,
    price_slider_cny: 0,
    languageCodeIndex: 0,
    filter: {
      page: 1,
      pageSize: 20,
      sort_type: 1,
      teach: "english",
      is_native: !1,
      is_trial: !1,
      country: ""
    },
    filter_form_obj: {
      id: "form",
      open: !1,
      filter_cells: [{
        title: "达人来自",
        key: "teacher_origin"
      }, {
        title: "达人特点",
        key: "teacher_feature"
      }, {
        title: "价格范围",
        key: "teacher_price"
      }, {
        title: "希望服务的时间段",
        key: "teach_time"
      }]
    }
  },

  //zl获取达人信息
  onLoad: function(options) {
    var that = this
    wx.request({
      url: config.service.listUrl,
      success: function(res) {
        console.log(res.data)
        that.setData({
          cater_info: res.data
        })
      },
      fail: function(res) {
        console.log(res.data)
      }
    })
  },
  //zl：获取达人详细信息
  bindToDetail: function(e) {
    // console.log(e)
    wx.navigateTo({
      url: "../teacher/profile/profile?id=" + e.currentTarget.id
    });
  },

  filterFormToggle: function(t) {
    var a = t.currentTarget.id,
      e = this.data.filter_form_obj;
    e.id == a ? e.open = !e.open : e.open = !1, this.setData({
      filter_form_obj: e
    });
  },
  bindViewTap: function() {
    wx.navigateTo({
      url: "../logs/logs"
    });
  },

  onPullDownRefresh: function() {
    this.data.page = 1, this.fetchTeacherListData(), setTimeout(function() {
      wx.stopPullDownRefresh();
    }, 2e3);
  },
  onReachBottom: function(t) {
    var a = this;
    a.data.hasMore && a.fetchTeacherListData();
  },

  fetchTeacherListData: function() {
    var t = this,
      a = this,
      i = a.data.filter;
    i.page = a.data.page;
    var r = Object.assign({}, i);
    delete r.within, delete r.tags, Array.isArray(i.tags) && (r.tags_list = i.tags.join(",")),
      Array.isArray(i.within) && (r.within_list = i.within.join(",")), e.default.getTeachersList({
        data: r,
        success: function(e) {
          var r = a.data.teacher_list;
          if (e && e.data) {
            1 === i.page && (r = []);
            var s = e.data.data;
            s && s.length >= 0 && (s.forEach(t.mergeTeacherInfo), s.length < a.data.filter.pageSize ? a.setData({
              teacher_list: r.concat(s),
              hasMore: !1
            }) : a.setData({
              teacher_list: r.concat(s),
              hasMore: !0,
              page: a.data.page + 1
            }));
          }
        }
      });
  },
  mergeTeacherInfo: function(t) {
    t.trial_price_cny = r.default.convertCurrencyToCNY(t.teacher_info_obj.trial_price_usd, c.globalData.currencyDatum),
      t.min_price_cny = r.default.convertCurrencyToCNY(t.teacher_info_obj.min_price_usd, c.globalData.currencyDatum),
      t.teacher_avatar_file = s.CDN_ADDR + t.avatar_file_name + "_Avatar.jpg", t.teacher_country_flag = "/images/flags/" + t.origin_country_id.toLowerCase() + "3x.png",
      t.is_pro && "0.0" === t.teacher_info_obj.pro_rating && !t.is_pro && "0.0" === t.teacher_info_obj.tutor_rating ? t.show_new_teacher_badge = !0 : t.show_new_teacher_badge = !1;
  },
  onImageError: function(t) {
    var a = this;
    i.default.errImgFun(t, a);
  },
  filterLearnLanguage: function(t) {
    var a = this,
      e = t.detail.value,
      i = this.data.ALL_LANGUAGE_DATUM[e].v;
    this.data.page = 1, this.data.filter.teach = i, this.fetchTeacherListData(), this.selectCountryViaTeach(),
      this.childTags = [], this.allChildTags.forEach(function(t) {
        if (t.language === a.data.filter.teach) {
          var e = Object.assign({}, t);
          e.checked = !1, a.childTags.push(e);
        }
      }), this.data.filter.tags && -1 !== this.data.filter.tags.indexOf("5") ? this.setData({
        TEACHER_CHILD_TAGS: this.childTags,
        languageCodeIndex: t.detail.value
      }) : this.setData({
        languageCodeIndex: t.detail.value
      });
  },
  selectTeacherTags: function(t) {
    var e = this.data.TEACHER_TAG_DATUM,
      i = t.detail.value;
    i.indexOf("") === i.length - 1 ? i = [""] : -1 !== i.indexOf("") && i.splice(i.indexOf(""), 1);
    for (var r = 0; r < e.length; r++) - 1 != i.indexOf(e[r].v + "") ? e[r].checked = !0 : e[r].checked = !1;
    this.data.filter.tags = i, i && -1 !== i.indexOf("5") ? this.setData(a({}, this.data, {
      filter: this.data.filter,
      TEACHER_TAG_DATUM: this.data.TEACHER_TAG_DATUM,
      TEACHER_CHILD_TAGS: this.childTags
    })) : (this.data.filter.child_tags_list = "", this.childTags.forEach(function(t, a, e) {
      e[a].checked = !1;
    }), this.setData(a({}, this.data, {
      filter: this.data.filter,
      TEACHER_TAG_DATUM: this.data.TEACHER_TAG_DATUM,
      TEACHER_CHILD_TAGS: []
    })));
  },
  selectCountryViaTeach: function() {
    var t = this;
    this.data.filter && this.data.filter.teach && (this.data.searchCountries = "", Object.keys(n.COUNTRIES_VIA_LANGUAGE).forEach(function(a) {
      if (a === t.data.filter.teach) {
        var e = n.COUNTRIES_VIA_LANGUAGE[a];
        t.setData({
          searchCountries: e
        });
      }
    }));
  },
  selectCountry: function(t) {
    var e = this.data.filter;
    void 0 === t.currentTarget.dataset.country ? e.country = "" : e.country = t.currentTarget.dataset.country.v,
      this.setData(a({}, this.data, {
        filter: e
      }));
  },
  selectFeatureNative: function() {
    var t = this.data.filter;
    t.is_native = !t.is_native, this.setData(a({}, this.data, {
      filter: t
    }));
  },
  selectFeatureSpeak: function(t) {
    var e = this.data.filter,
      i = t.currentTarget.dataset.speak;
    e.speak === i ? e.speak = "" : e.speak = i, this.setData(a({}, this.data, {
      filter: e
    }));
  },
  selectFeatureTrial: function() {
    var t = this.data.filter;
    t.is_trial = !t.is_trial, this.setData(a({}, this.data, {
      filter: t
    }));
  },
  selectTeacherType: function(t) {
    var e = this.data.filter,
      i = this.data.TEACHER_TYPES;
    e.teacher_type = t.currentTarget.dataset.teacherType.v, this.setData(a({}, this.data, {
      filter: e,
      TEACHER_TYPES: i
    }));
  },
  selectTeacherChildTags: function(t) {
    if (t.detail.value) {
      this.childTags.forEach(function(a, e, i) {
        i[e].checked = -1 !== t.detail.value.indexOf(a.id.toString());
      });
      var e = this.data.filter;
      e.child_tags_list = t.detail.value.join(", "), this.setData(a({}, this.data, {
        filter: e,
        TEACHER_CHILD_TAGS: this.childTags
      }));
    }
  },
  selectTeachTime: function(t) {
    var a = this.data.TEACH_TIME_DATUM,
      e = t.detail.value;
    e.indexOf("") === e.length - 1 ? e = [""] : -1 !== e.indexOf("") && e.splice(e.indexOf(""), 1);
    for (var i = 0; i < a.length; i++) - 1 != e.indexOf(a[i].v + "") ? a[i].checked = !0 : a[i].checked = !1;
    this.data.filter.within = e, this.setData({
      filter: this.data.filter,
      TEACH_TIME_DATUM: this.data.TEACH_TIME_DATUM
    });
  },
  sliderChange: function(t) {
    var a = r.default.convertCNYToApproachCent(t.detail.value, c.globalData.currencyDatum),
      e = r.default.convertCurrencyToCNY(a, c.globalData.currencyDatum);
    this.data.filter.price_usd = "0-" + a, this.setData({
      filter: this.data.filter,
      price_slider_cny: e
    });
  },
  clearFilter: function() {
    var t = {
      page: 1,
      pageSize: 20,
      sort_type: 1
    };
    this.data.page = 1, this.data.filter_form_obj.open = !1, this.setData({
      filter: t,
      TEACH_TIME_DATUM: n.TEACH_TIME_DATUM,
      TEACHER_TAG_DATUM: n.TEACHER_TAG_DATUM,
      TEACHER_PRICE_VALUE: this.data.TEACHER_PRICE_VALUE,
      filter_form_obj: this.data.filter_form_obj
    }), this.fetchTeacherListData();
  },
  filterTeacherList: function() {
    var t = this.data.filter;
    this.data.page = 1, this.data.filter_form_obj.open = !1, this.setData({
      filter: t,
      filter_form_obj: this.data.filter_form_obj
    }), this.fetchTeacherListData();
  },
  getCurrentUserInfo: function() {
    var t = this;
    c.globalData.userInfo ? this.setData({
      userInfo: c.globalData.userInfo,
      hasUserInfo: !0
    }) : this.data.canIUse ? c.userInfoReadyCallback = function(a) {
      t.setData({
        userInfo: a.userInfo,
        hasUserInfo: !0
      });
    } : wx.getUserInfo({
      success: function(a) {
        c.globalData.userInfo = a.userInfo, t.setData({
          userInfo: a.userInfo,
          hasUserInfo: !0
        });
      }
    });
  },
  onShareAppMessage: function(t) {
    return "button" === t.from && console.log(t.target), {
      title: "",
      path: "/pages/teacher/teacher",
      success: function(t) {
        console.log("sucess");
      },
      fail: function(t) {
        console.log("fail");
      }
    };
  },
  onReady: function() {
    wx.setNavigationBarTitle({
      title: "乐活城市达人"
    });
  }
});